package com.ruoyi.app.controller;

import com.ruoyi.app.utils.AppUserUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wuliu.controller.TLeaveMessageController;
import com.ruoyi.web.wuliu.domain.AppUser;
import com.ruoyi.web.wuliu.domain.TPost;
import com.ruoyi.web.wuliu.domain.TReport;
import com.ruoyi.web.wuliu.domain.TReview;
import com.ruoyi.web.wuliu.service.ITLeaveMessageService;
import com.ruoyi.web.wuliu.service.ITPostService;
import com.ruoyi.web.wuliu.service.ITReviewService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 帖子Controller
 * 
 * @author ruoyi
 * @date 2023-12-05
 */
@ApiOperation("帖子接口")
@RestController
@RequestMapping("/app/wuliu/post")
public class AppTPostController extends BaseController
{
    @Autowired
    private ITPostService tPostService;

    @Autowired
    private ITReviewService tReviewService;
    /**
     * 查询帖子列表
     */
    @ApiOperation("查看帖子")
    @GetMapping("/list")
    public TableDataInfo list(TPost tPost)
    {
        startPage();
        List<TPost> list = tPostService.selectTPostList(tPost);
        return getDataTable(list);
    }

    /**
     * 获取帖子详细信息
     */
    @ApiOperation("获取帖子详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(tPostService.getById(id));
    }

    /**
     * 新增帖子
     */
    @ApiOperation("新增帖子")
    @PostMapping
    public AjaxResult add(@RequestBody TPost tPost)
    {
        return toAjax(tPostService.insertTPost(tPost));
    }

    /**
     * 修改帖子
     */
    @ApiOperation("修改帖子")
    @PutMapping
    public AjaxResult edit(@RequestBody TPost tPost)
    {
        return toAjax(tPostService.updateTPost(tPost));
    }

    /**
     * 删除帖子
     */
    @ApiOperation("删除帖子")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tPostService.deleteTPostByIds(ids));
    }

    /**
     * 点赞帖子
     */
    @ApiOperation("点赞帖子")
    @GetMapping(value = "/giveLike/{id}")
    public AjaxResult giveLike(@PathVariable("id") Integer id)
    {
        return toAjax(tPostService.giveLike(id));
    }


    /**
     * 评论帖子
     */
    @ApiOperation("评论帖子")
    @PostMapping(value = "/review")
    public AjaxResult review(@RequestBody TReview tReview)
    {
        return toAjax(tReviewService.insertTReview(tReview));
    }

    /**
     * 取消点赞帖子
     */
    @ApiOperation("取消点赞帖子")
    @GetMapping(value = "/cancelGiveLike/{id}")
    public AjaxResult cancelGiveLike(@PathVariable("id") Integer id)
    {
        return toAjax(tPostService.cancelGiveLike(id));
    }

    /**
     * 举报帖子
     */
    @ApiOperation("举报帖子")
    @PostMapping(value = "/report")
    public AjaxResult report(@RequestBody TReport report)
    {
        return toAjax(tPostService.report(report));
    }


}
